package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.mapper.ProductTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.ProductTask;
import com.ruoyi.product.service.IProductTaskService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品任务Controller
 *
 * @author 林道敬
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/task")
public class ProductTaskController extends BaseController
{
    @Autowired
    private IProductTaskService productTaskService;
    @Autowired
    private ProductTaskMapper productTaskMapper;

    @GetMapping("/testAutoId")
    public long list(){
        ProductTask productTask = new ProductTask();
        productTask.setOutTradeNo("123456");
        productTaskMapper.insert(productTask);
        return productTask.getId();
    }
    /**
     * 查询商品任务列表
     */
    @RequiresPermissions("product:task:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductTask productTask)
    {
        startPage();
        List<ProductTask> list = productTaskService.selectProductTaskList(productTask);
        return getDataTable(list);
    }

    /**
     * 导出商品任务列表
     */
    @RequiresPermissions("product:task:export")
    @Log(title = "商品任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductTask productTask)
    {
        List<ProductTask> list = productTaskService.selectProductTaskList(productTask);
        ExcelUtil<ProductTask> util = new ExcelUtil<ProductTask>(ProductTask.class);
        util.exportExcel(response, list, "商品任务数据");
    }

    /**
     * 获取商品任务详细信息
     */
    @RequiresPermissions("product:task:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(productTaskService.selectProductTaskById(id));
    }

    /**
     * 新增商品任务
     */
    @RequiresPermissions("product:task:add")
    @Log(title = "商品任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductTask productTask)
    {
        return toAjax(productTaskService.insertProductTask(productTask));
    }

    /**
     * 修改商品任务
     */
    @RequiresPermissions("product:task:edit")
    @Log(title = "商品任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductTask productTask)
    {
        return toAjax(productTaskService.updateProductTask(productTask));
    }

    /**
     * 删除商品任务
     */
    @RequiresPermissions("product:task:remove")
    @Log(title = "商品任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productTaskService.deleteProductTaskByIds(ids));
    }
}
